import { SkillInfoPanel } from "../SkillInfoPanel";
import { GLabel } from "../../../../../com/mui/controls/GLabel";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { GCheckBox } from "../../../../../com/mui/controls/GCheckBox";
import { ModuleBg } from "../../common/ModuleBg";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { Language } from "../../../../../extend/language/Language";
import { ResouceConst } from "../../../../component/gconst/ResouceConst";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { SkillDetailPanel } from "./SkillDetailPanel";
import { SkillBookPanel } from "./SkillBookPanel";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { ObjCreate } from "../../common/ObjCreate";
import { SystemSetter } from "../../system/SystemSetter";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { SkillInfo } from "../../../model/SkillInfo";
import { Cache } from "../../../cache/Cache";
import { MsgManager } from "../../../manager/MsgManager";
import { SkillItem } from "../SkillItem";
import { ESkillTargetSelect } from "../../../../../Message/Public/ESkillTargetSelect";
import { ESkillType } from "../../../../../Message/Public/ESkillType";
import { LadderBattlefieldUtil } from "../../ladderBattlefield/LadderBattlefieldUtil";
import { ToolTipInfo } from "../../../model/ToolTipInfo";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
type int = number;
//class SkillCareerInfoPanel
    
    export  class SkillCareerInfoPanel extends SkillInfoPanel
    {
        constructor()
        {
            super();
            this._skillName = new GLabel();
            this._skillLevel = new GLabel();
            this._roleLevel = new GLabel();
            this._roleExp = new GLabel();
            this._copperNeed = new GLabel();
            this._learnBtn = new GButton();
            this._info = new Object /* flash.text.TextField */();
            this._autoUseCheck = new GCheckBox();
            this._autoUseTarget = new GCheckBox();
            this._bg = new ModuleBg();
            this._info = new Object /* flash.text.TextField */();
            this._info.selectable = false;
            this._info.textColor = 13026729;
            this._info.filters = [FilterConst.nameGlowFilter];
            this._info.text = Language.getString(20674);
            this._info.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._info.width = 173;
            this.createMainInfo();
            this.createConditionsInfo();
            addChild(this._bg);
            return;
        }

        /* internal  */createMainInfo(): void
        {
            this._bg.addItem(ResouceConst.getScaleBitmap("WindowCenterB"), {"x": 4, "y": 4, "width": width - 8, "height": 50});
            this._bg.addItem(GlobalClass.getBitmap(ImagesConst.PackItemBg), {"x": 15, "y": 10});
            this._bg.addItem(this._skillName, {"x": 60, "y": 12, "width": 150, "height": 18, "styleName":"GLabel"});
            this._bg.addItem(this._autoUseCheck, {"x": 108, "y": 11, "width": 150, "styleName":"GCheckBox", "label": Language.getString(20675)});
            this._bg.addItem(this._autoUseTarget, {"x": 108, "y": 11, "width": 150, "styleName":"GCheckBox", "label": Language.getString(20779)});
            this._bg.addItem(this._skillLevel, {"x": 60, "y": 28, "width": 150, "height": 18, "styleName":"GLabel"});
            this._autoUseCheck.addEventListener(flash.events.Event.CHANGE, this.onAutoUseChangeHandler);
            this._autoUseTarget.addEventListener(flash.events.Event.CHANGE, this.onAutoUseTargetChangeHandler);
            return;
        }

        /* internal  */createDetailInfo(): void
        {
            if (!this._detailPanel) 
            {
                this._detailPanel = new SkillDetailPanel();
            }
            if (!this._detailPanel.parent) 
            {
                this._bg.addItem(this._detailPanel, {"x": 4, "y": 62});
            }
            if (this._getBookPanel && this._getBookPanel.parent) 
            {
                this._getBookPanel.parent.removeChild(this._getBookPanel);
                this._getBookPanel.dispose();
            }
            return;
        }

        /* internal  */createSkillBookInfo(): void
        {
            if (!this._getBookPanel) 
            {
                this._getBookPanel = new SkillBookPanel();
            }
            if (!this._getBookPanel.parent) 
            {
                this._bg.addItem(this._getBookPanel, {"x": 4, "y": 62});
            }
            if (this._detailPanel && this._detailPanel.parent) 
            {
                this._detailPanel.parent.removeChild(this._detailPanel);
                this._detailPanel.dispose();
            }
            return;
        }

        /* internal  */createConditionsInfo(): void
        {
            this._bg.addItem(GlobalClass.getBitmap("Line"), {"x":-40, "y": 275});
            this._bg.addItem(new GLabel(), {"x": 80, "y": 283, "htmlText": HTMLUtil.addColor("<font size=\'14\'>" + Language.getString(20676) + "</font>", "#FFF72A"), "filters":[FilterConst.nameGlowFilter]});
            this._bg.addItem(new GLabel(), {"x": 4, "y": 305, "htmlText": HTMLUtil.addColor(Language.getString(20677) + "：", "#F5C767")});
            this._bg.addItem(new GLabel(), {"x": 4, "y": 325, "htmlText": HTMLUtil.addColor(Language.getString(20678) + "：", "#F5C767")});
            this._bg.addItem(new GLabel(), {"x": 4, "y": 345, "htmlText": HTMLUtil.addColor(Language.getString(20679) + "：", "#F5C767")});
            this._bg.addItem(this._roleLevel, {"x": 65, "y": 303, "styleName":"GLabel"});
            this._bg.addItem(this._roleExp, {"x": 65, "y": 323, "styleName":"GLabel"});
            this._bg.addItem(this._copperNeed, {"x": 65, "y": 343, "styleName":"GLabel"});
            this._oneKeyLearn = ObjCreate.createCheckBox("", 135, 311, 20, 20);
            this._oneKeyLearn.addEventListener(flash.events.Event.CHANGE, this.oneKeyLearnSelectedChange);
            this._oneKeyLearn.selected = SystemSetter.currentSetter.isOneKeyUpgrateSkill;
            this._txtOneKeyLearn = ObjCreate.createGTextField(Language.getString(80196), this._oneKeyLearn.x + 20, this._oneKeyLearn.y + 2, 120, 20);
            this._bg.addItem(this._oneKeyLearn, {});
            this._bg.addItem(this._txtOneKeyLearn, {});
            this._learnBtn.setSize(70, 26);
            this._learnBtn.label = Language.getString(20680);
            this._learnBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onLearnBtnClickHandler);
            this._bg.addItem(this._learnBtn, {"x": 135, "y": 335, "styleName":"ButtonSpecial"});
            this._bg.addItem(this._info, {"x": 25, "y": 365});
            return;
        }

        /* internal  */oneKeyLearnSelectedChange(arg1: Object /* flash.events.Event */): void
        {
            if (flash.utils.getTimer() < this._nextCanOpOnekeyLearnTime) 
            {
                this._oneKeyLearn.selected = !this._oneKeyLearn.selected;
                return;
            }
            this._nextCanOpOnekeyLearnTime = flash.utils.getTimer() + 1000;
            SystemSetter.localSetter.isOneKeyUpgrateSkill = this._oneKeyLearn.selected;
            Dispatcher.dispatchEvent(new DataEvent(EventName.Sys_SaveInfoNotShowInWindow));
            return;
        }

        /* internal  */onAutoUseChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            _skillMapData.autoUse = this._autoUseCheck.selected;
            SystemSetter.localSetter.skillIdDic[_skillMapData.position] = _skillMapData.autoUse ? 1 : 0;
            var loc1=SystemSetter.localSetter.getString();
            Dispatcher.dispatchEvent(new DataEvent(EventName.Sys_SaveInfoNotShowInWindow, loc1));
            return;
        }

        /* internal  */onAutoUseTargetChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            SystemSetter.localSetter.autoUseTargetDic[_skillMapData.position] = this._autoUseTarget.selected ? 1 : 0;
            var loc1=SystemSetter.localSetter.getString();
            Dispatcher.dispatchEvent(new DataEvent(EventName.Sys_SaveInfoNotShowInWindow, loc1));
            return;
        }

        /* internal  */onLearnBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.levelUpReq(_skillMapData);
            return;
        }

        public /* override */ levelUpReq(arg1: SkillInfo): void
        {
            if (!arg1) 
            {
                return;
            }
            if (this._reqing) 
            {
                return;
            }
            if (_skillMapData.nextSkill.needCoin > Cache.instance.login.loginGame.money.coin + Cache.instance.login.loginGame.money.coinBind) 
            {
                MsgManager.showRollTipsMsg(Language.getString(20681));
                Dispatcher.dispatchEvent(new DataEvent(EventName.ShopMallAutoBuyCoin, _skillMapData.nextSkill.needCoin));
                return;
            }
            this._reqing = true;
            this._learnBtn.enabled = false;
            if (arg1.learned) 
            {
                if (this._oneKeyLearn.selected) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.skillUpgrateAllReq));
                }
                else 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.skillUpgradeReq, arg1.tSkill.skillId));
                }
            }
            else 
            {
                if (this._oneKeyLearn.selected) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.skillUpgrateAllReq));
                }
                else 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.skillLearnReq, arg1.tSkill.skillId));
                }
                if (Cache.instance.guide.guideSkillLearn) 
                {
                    guideHide();
                }
            }
            return;
        }

        public /* override */ updateInfo(arg1: SkillInfo): void
        {
            this._reqing = false;
            _skillMapData = arg1;
            _skill = _skillMapData.tSkill;
            if (_skillMapData.learned) 
            {
                this.createDetailInfo();
                this._detailPanel.updateData(_skillMapData);
            }
            else 
            {
                this.createSkillBookInfo();
                this._getBookPanel.updateData(_skillMapData);
            }
            var loc1=_skillMapData.levelMax ? HTMLUtil.addColor(Language.getString(20682), "#00ff00") : HTMLUtil.addColor(Language.getString(20683), "#ff0000");
            this._skillName.text = _skillMapData.tSkill.skillName;
            if (_skillMapData.learned) 
            {
                this._skillLevel.htmlText = Language.getString(20684) + _skillMapData.tSkill.skillLevel + loc1;
            }
            else 
            {
                this._skillLevel.htmlText = Language.getString(20684) + "0" + loc1;
            }
            if (!this._skillItem) 
            {
                this._skillItem = new SkillItem();
                this._bg.addItem(this._skillItem, {"x": 18, "y": 13});
            }
            this._skillItem.data = _skillMapData;
            this._skillItem.toolTipDataFunction = this.getToolTipData;
            this.updateCondition();
            if (_skillMapData.position <= 2) 
            {
                this._autoUseCheck.visible = true;
                this._autoUseCheck.selected = _skillMapData.autoUse;
                this._autoUseTarget.visible = false;
            }
            else if (_skillMapData.tSkill.targetSelect == ESkillTargetSelect._ESkillTargetSelectMouse && !(_skillMapData.skillType == ESkillType._ESKillTypeTransfer)) 
            {
                this._autoUseTarget.visible = true;
                this._autoUseTarget.selected = SystemSetter.localSetter.autoUseTargetDic[_skillMapData.position] == 1;
                this._autoUseCheck.visible = false;
            }
            else 
            {
                this._autoUseCheck.visible = false;
                this._autoUseTarget.visible = false;
            }
            return;
        }

        public /* override */ updateCondition(): void
        {
            if (!_skillMapData) 
            {
                return;
            }
            var loc1="";
            var loc2=true;
            loc1 = _skillMapData.nextSkill.levelLimited + Language.getString(20685);
            if (_skillMapData.nextSkill.levelLimited > Cache.instance.role.entityInfo.level) 
            {
                loc2 = false;
                this._roleLevel.htmlText = HTMLUtil.addColor(loc1, "#ff1414");
            }
            else 
            {
                this._roleLevel.htmlText = HTMLUtil.addColor(loc1, "#6DFF00");
            }
            loc1 = _skillMapData.nextSkill.needExperience + "";
            if (_skillMapData.nextSkill.needExperience > Cache.instance.role.roleInfo.experience) 
            {
                loc2 = false;
                this._roleExp.htmlText = HTMLUtil.addColor(loc1, "#ff1414");
            }
            else 
            {
                this._roleExp.htmlText = HTMLUtil.addColor(loc1, "#FFE56C");
            }
            loc1 = _skillMapData.nextSkill.needCoin + "";
            if (_skillMapData.nextSkill.needCoin > Cache.instance.login.loginGame.money.coin + Cache.instance.login.loginGame.money.coinBind) 
            {
                this._copperNeed.htmlText = HTMLUtil.addColor(loc1, "#ff1414");
            }
            else 
            {
                this._copperNeed.htmlText = HTMLUtil.addColor(loc1, "#FFE56C");
            }
            if (loc2 && !(_skill.preSkillId == 0) && !_skillMapData.preLearned) 
            {
                loc2 = false;
            }
            if (_skillMapData.learned) 
            {
                if (_skillMapData.levelMax) 
                {
                    this._learnBtn.label = Language.getString(20697);
                }
                else 
                {
                    this._learnBtn.label = Language.getString(20680);
                }
            }
            else 
            {
                this._learnBtn.label = Language.getString(20686);
            }
            if (_optAble) 
            {
                this._learnBtn.enabled = loc2 && !_skillMapData.levelMax;
            }
            if (LadderBattlefieldUtil.isInLadderBattlefield) 
            {
                this._learnBtn.label = Language.getString(20697);
                this._learnBtn.enabled = false;
            }
            return;
        }

        /* internal  */enableOnekeyLearn(arg1: Boolean): void
        {
            this._oneKeyLearn.visible = arg1;
            this._oneKeyLearn.mouseEnabled = arg1;
            this._txtOneKeyLearn.visible = arg1;
            this._txtOneKeyLearn.mouseEnabled = arg1;
            return;
        }

        public /* override */ guideSkillLearn(arg1: Function): void
        {
            arg1(this._learnBtn.x + this._learnBtn.width, this._learnBtn.y + this._learnBtn.height / 2, this._learnBtn);
            return;
        }

        /* internal  */getToolTipData(arg1: SkillItem): ToolTipInfo
        {
            return (arg1.data as SkillInfo).getToolTipInfo();
        }

        /* internal */ /* var */_skillItem: SkillItem;

        /* internal */ /* var */_bg: ModuleBg;

        /* internal */ /* var */_skillName: GLabel;

        /* internal */ /* var */_skillLevel: GLabel;

        /* internal */ /* var */_roleLevel: GLabel;

        /* internal */ /* var */_roleExp: GLabel;

        /* internal */ /* var */_copperNeed: GLabel;

        /* internal */ /* var */_detailPanel: SkillDetailPanel;

        /* internal */ /* var */_getBookPanel: SkillBookPanel;

        protected /* var */_learnBtn: GButton;

        /* internal */ /* var */_info: Object /* flash.text.TextField */;

        /* internal */ /* var */_oneKeyLearn: GCheckBox;

        /* internal */ /* var */_txtOneKeyLearn: GTextFiled;

        /* internal */ /* var */_nextCanOpOnekeyLearnTime: int=0;

        protected /* var */_autoUseCheck: GCheckBox;

        protected /* var */_autoUseTarget: GCheckBox;

        /* internal */ /* var */_reqing: Boolean;
    }
